package com.gene.controller.members;

import com.gene.pojo.entity.Members;
import com.gene.service.IMembersService;
import com.gene.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 二级会员
 */
@Controller
@RequestMapping("/gene-safe/members")
public class MembersController {

    @Autowired
    private IMembersService iMembersService;
    /**
     * 根据用户Id返回所有的二级会员
     * @return
     */
    @RequestMapping(value = "/query",method = RequestMethod.POST)
    @ResponseBody
    public ResultData query(@RequestParam(value = "userId") Integer userId){
        ResultData result=new ResultData();
        List<Members> list=iMembersService.query(userId);
        if(list.size()>0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }
        return  result;
    }

    /**
     * 根据用户id添加会员
     * @param sid
     * @param uid
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public ResultData save(@RequestParam("sid") Integer sid,@RequestParam("uid") Integer uid){
        ResultData result=new ResultData();
        boolean bool=iMembersService.save(sid,uid);
        if(bool){
            result.setStatus("1");
            result.setMsg("添加成功！");
        }else{
            result.setStatus("0");
            result.setMsg("添加失败！");
        }
        return  result;
    }
}
